<div id="adminLayout" style="position:relative;float:left;width:100%;height:480px;"></div>
<script>
                var adminLayout = new dhtmlXLayoutObject("adminLayout","2U");
                adminLayout.setImagePath("<?=$this->baseUrl?>/img/");
                adminLayout.cells("a").setText("System Administration");
                adminLayout.cells("a").setWidth(400);
		adminLayout.cells("b").setText('');
                adminLayout.setEffect('collapse',true);
                adminAccordion = adminLayout.cells('a').attachAccordion();
                        adminAccordion.setIconsPath("<?=$this->baseUrl?>/img/");
                        adminAccordion.addItem("systemObjects","System Objects");
			sysObjectsTree = adminAccordion.cells('systemObjects').attachTree();
			sysObjectsTree.setImagePath("<?=$this->baseUrl?>/img/");
			sysObjectsTree.insertNewChild(0,1,'Persons/Users');
			sysObjectsTree.attachEvent('onClick',onSystemObjectsTreeItemSelect);
			sysObjectsTree.insertNewChild(0,2,'Physical Plant');
			sysObjectsTree.insertNewChild(0,3,'NSDR Manager');
			//sysObjectsTree.insertNewChild(0,4,'Menu Manager');
			sysObjectsTree.insertNewChild(0,5,'Permissions Templates');
			sysObjectsTree.insertNewChild(0,6,'Prescriptions');
			sysObjectsTree.insertNewChild(0,7,'Note Templates');
			//sysObjectsTree.insertNewChild(0,8,'Formulary Manager');
			sysObjectsTree.insertNewChild(0,9,'Enumeration Manager');
			sysObjectsTree.insertNewChild(0,10,'Barcode Manager');
			sysObjectsTree.insertNewChild(0,11,'Services');
			sysObjectsTree.insertNewChild(0,12,'HL7');
			sysObjectsTree.closeAllItems();

                        adminAccordion.addItem("healthcloud","HealthCloud");
			healthCloudTree = adminAccordion.cells('healthcloud').attachTree();
			healthCloudTree.setImagePath("<?=$this->baseUrl?>/img/");
			healthCloudTree.insertNewChild(0,1,'CHMED');
			healthCloudTree.attachEvent('onClick',onHealthCloudTreeItemSelect);
			healthCloudTree.insertNewChild(0,2,'CHMED Pharmacies');
			healthCloudTree.closeAllItems();

		 adminAccordion.cells("systemObjects").open();

function onSystemObjectsTreeItemSelect(itemId) {
	itemName = sysObjectsTree.getItemText(itemId);
	switch (itemName) {
		case 'Persons/Users':
			changeAdminContainer(itemName,'<?=$this->baseUrl?>/admin-persons.raw');
			break;
		case 'CHMED Pharmacies':
			adminLayout.cells("b").setText(itemName);
			adminLayout.cells("b").attachURL('<?=$this->baseUrl?>/admin-pharmacies');
			break;
		case 'NSDR Manager':
			changeAdminContainer(itemName,'<?=$this->baseUrl?>/nsdr-manager.raw');
			break;
		//case 'Menu Manager':
		//	changeAdminContainer(itemName,'<?=$this->baseUrl?>/menu-manager.raw');
		//	break;
		case 'Permissions Templates':
			changeAdminContainer(itemName,'<?=$this->baseUrl?>/acl.raw');
			break;
		case 'Prescriptions':
			changeAdminContainer(itemName,'<?=$this->baseUrl?>/admin-prescriptions.raw');
			break;
		case 'Note Templates':
			changeAdminContainer(itemName,'<?=$this->baseUrl?>/clinical-notes-manager.raw');
			break;
		case 'Formulary Manager':
			changeAdminContainer(itemName,'<?=$this->baseUrl?>/formulary-manager.raw');
			break;
		case 'Enumeration Manager':
			changeAdminContainer(itemName,'<?=$this->baseUrl?>/enumerations-manager.raw');
			break;
		case 'Barcode Manager':
			changeAdminContainer(itemName,'<?=$this->baseUrl?>/admin-barcode.raw');
			break;
		case 'Services':
			changeAdminContainer(itemName,'<?=$this->baseUrl?>/admin-services.raw');
			break;
		case 'HL7':
			changeAdminContainer(itemName,'<?=$this->baseUrl?>/admin-hl7.raw');
			break;
		default:
			alert('\'' + itemName + '\' does not have an action defined');
	}
}

function changeAdminContainer(itemName,url) {
	if (url.substr(url.length-4) == '.raw') {
		url = url.substr(0,url.length-4);
	}
	adminLayout.cells("b").attachURL(url,true);
	adminLayout.cells("b").setText(itemName);
	return;

	var hasAdmin = true;
	var adminContainerId = 'adminContainer';
	var adminContainer = dojo.byId(adminContainerId);
	if (adminContainer == null) {
		hasAdmin = false;
		adminContainer = document.createElement('div');
		adminContainer.setAttribute('id',adminContainerId);
		adminContainer.style.height = '440px';
		adminContainer.style.position = 'relative';
		adminContainer.style.overflow = 'auto';
	}
	adminContainer.style.width = adminLayout.cells("b").getWidth() + 'px';
	dojo.xhrGet({
		url: url,
		handleAs: "text",
		load: function(data,ioArgs) {
			dojo.setInnerHTML(adminContainer,data);
			if (!hasAdmin) {
				var body = document.getElementsByTagName('body').item(0);
				body.appendChild(adminContainer);
			}
			adminLayout.cells("b").attachObject(adminContainerId);
			adminLayout.cells("b").setText(itemName);
			return data;
		},
		error: function(response, ioArgs) {
			console.error("HTTP status code: ", ioArgs.xhr.status);
			return response;
		}
	});
}

function onHealthCloudTreeItemSelect(itemId) {
	itemName = healthCloudTree.getItemText(itemId);
	switch (itemName) {
		case 'CHMED Pharmacies':
			adminLayout.cells("b").setText(itemName);
			adminLayout.cells("b").attachURL('<?=$this->baseUrl?>/admin-pharmacies');
			break;
		default:
			alert('\'' + itemName + '\' does not have an action defined');
	}
}
</script>
